<?php
	include("include0.php");
	header("Content-type: application/json");
	
	$verb = $_SERVER["REQUEST_METHOD"];
	//echo $verb;
	if($verb == "GET")
	{
		$arr = array();
		$rs = mysql_query("select EmployeeID, LastName, FirstName from Employees");
		
		while($obj = mysql_fetch_object($rs))
		{
				$arr[] = $obj;
		}
		// add the header line to specify that the content type is JSON
		
	
		echo "{\"data\":" . json_encode($arr) . "}";
	}
	
	if($verb == "POST")
	{
		$lastName = mysql_real_escape_string($_POST["LastName"]);
    	$employeeId = mysql_real_escape_string($_POST["EmployeeID"]);

    	$rs = mysql_query("UPDATE Employees SET LastName = '" .$lastName ."' WHERE EmployeeID = " .$employeeId);

		//$sql = sprintf("update Employees set LastName = '%s' where employeeID = '%s'", $lastName, $employeeId);
		//$rs = mysql_query("update Employees set LastName = '" . $lastName . "' where EmployeeID = ". $employeeId);
		
		if($rs)
		{
			echo json_encode($rs);	
		}
		else
		{
			header("HTTP / 500 | Internal Server Errror");
			echo "Update failed for EmployeeID: ". $employeeId;	
		}
	}

?>